<?php

/**
 * @author @author Samrat Khan & Sadik Sarfaraz - Apr 10, 2013
 */
/**
 * 
 * @param string $orderby You can order data using Ascending/Descending, use ASC or DESC onto this parameter
 * @param string $columnname by which column name this data will be sorted is defined by this
 * @param string $db Common database connection string parameter
 * @return string $rows Returning the rows of a table
 */
function getUsers($orderby, $columnname, $db) {
    $query = 'SELECT * FROM wms_users ORDER BY '.$columnname.' '.$orderby.'';
    try {
        $stmt = $db->prepare($query);
        $stmt->execute();
    } catch (PDOException $ex) {
        die("Failed to run query: " . $ex->getMessage());
    }
    $rows = $stmt->fetchAll();
    return $rows;
}
/**
 * 
 * @param numeric $id is used to get customer id from customerinfo table
 * @param string $db Common database connection string parameter
 * @return string $rows1 Returning the cusname from customerinfo table
 */
function getCustomer($id, $db){
	$query = "SELECT cus_id, cusname FROM customerinfo WHERE cus_id={$id} LIMIT 1";
    try {
        $stmt = $db->prepare($query);
        $stmt->execute();
    } catch (PDOException $ex) {
        die("Failed to run query: " . $ex->getMessage());
    }
    $row1 = $stmt->fetch();
    return $row1['cusname'];
}
/**
 * 
 * @param numeric $id is used to get customer id from customerinfo table
 * @param string $db Common database connection string parameter
 * @return string $CI Returning the cusname from customerinfo table and shows in drop down menu
 */
function getCustomers($id, $db) {
    $query = "SELECT cus_id, cusname FROM customerinfo";
        try {
            $stmt = $db->prepare($query);
            $stmt->execute();
        } catch (PDOException $ex) {
            die("Failed to run query: " . $ex->getMessage());
        }
        $rows = $stmt->fetchAll();

        foreach($rows as $row1) {
            $CI.="<option value='{$row1["cus_id"]}'>";
                $CI.=$row1['cusname'];
            $CI.="</option>";
            $CI++;
        }
        return $CI;
}
/**
 * 
 * @param string $db Common database connection string parameter
 * @return string $UT Returning the user type name from usertype table and shows in drop down menu
 */
function getUserTypeName($db) {
    $query = "SELECT u_type_id, u_type_name FROM usertype";
        try {
            $stmt = $db->prepare($query);
            $stmt->execute();
        } catch (PDOException $ex) {
            die("Failed to run query: " . $ex->getMessage());
        }
        $rows = $stmt->fetchAll();

        foreach($rows as $row1) {
            $UT.="<option value='{$row1["u_type_id"]}'>";
                $UT.=$row1['u_type_name'];
            $UT.="</option>";
            $UT++;
        }
        return $UT;
}
?>